<%@ include file="/WEB-INF/pages/common/taglibs.jsp" %>
<%@ include file="/WEB-INF/pages/common/checkpermission.jsp" %>
<codelookup:codeCollection id="roleList" codeType="CODE_TYPE" filterName="CODE_FILTER" filterParams="ROLE_LIST"/>
<codelookup:codeCollection id="deptList" codeType="DEPT_LIST"/>

<script type="text/javascript">
    function saveRecord() {
        $("td").removeClass("showErrorClass");
        var currentForm = document.forms["updateUserForm"];
        currentForm.elements["userModel.userName"].value = currentForm.elements["userModel.userName"].value.trim();
        currentForm.elements["userModel.userPassword"].value = currentForm.elements["userModel.userPassword"].value.trim();
        currentForm.elements["userModel.confirmPassword"].value = currentForm.elements["userModel.confirmPassword"].value.trim();
        if (isEmpty(currentForm.elements["userModel.userName"].value)) {
            currentForm.elements["userModel.userName"].focus();
            $(currentForm.elements["userModel.userName"]).parents("tr:first").find("td:first").addClass("showErrorClass");
            alert('<s:text name="label.userName.required"/>');
            return;
        }
        if (isEmpty(currentForm.elements["userModel.userPassword"].value)) {
            currentForm.elements["userModel.userPassword"].focus();
            $(currentForm.elements["userModel.userPassword"]).parents("tr:first").find("td:first").addClass("showErrorClass");
            alert('<s:text name="label.password.required"/>');
            return;
        }
        if (isEmpty(currentForm.elements["userModel.confirmPassword"].value)) {
            currentForm.elements["userModel.confirmPassword"].focus();
            $(currentForm.elements["userModel.confirmPassword"]).parents("tr:first").find("td:first").addClass("showErrorClass");
            alert('<s:text name="label.confirmPassword.required"/>');
            return;
        }
        if (currentForm.elements["userModel.userPassword"].value != currentForm.elements["userModel.confirmPassword"].value) {
            alert('<s:text name="label.password.different"/>');
            return;
        }
        if (!atLeastOneRecordChecked('updateUserFormDiv')) {
            alert('<s:text name="label.select.atleast.one.permission"/>');
            return;
        }
        submitForm("updateUserForm", "save.action");
    }

    function cancelRecord() {
        submitForm("updateUserForm", "search.action");
    }

    function changeUserRole(){
       var currentForm = document.forms["updateUserForm"];
        var userRole=currentForm.elements["userModel.userRole"].value;
        if(userRole=="A"){
            o = document.getElementById("updateUserFormDiv");
            var resultList = o.getElementsByTagName("input");
            for (var i = 0; i < resultList.length; i++) {
                if (resultList[i].type == 'checkbox') {
                    resultList[i].checked=true;
                }
            }
            document.getElementById("hiddenTr1").style.display="none";
            document.getElementById("hiddenTr2").style.display="none";
            document.getElementById("hiddenTr3").style.display="none";
            document.getElementById("hiddenTr4").style.display="none";
            document.getElementById("hiddenTr5").style.display="none";
            document.getElementById("hiddenTr6").style.display="none";
            document.getElementById("hiddenTr7").style.display="none";
            document.getElementById("hiddenTr8").style.display="none";
            document.getElementById("hiddenTr9").style.display="none";
            document.getElementById("hiddenTr10").style.display="none";
            document.getElementById("hiddenTr11").style.display="none";
        }else{
            o = document.getElementById("updateUserFormDiv");
            o.style.display="";
            resultList = o.getElementsByTagName("input");
            for (var i = 0; i < resultList.length; i++) {
                if (resultList[i].type == 'checkbox') {
                    resultList[i].checked=false;
                }
            }
            document.getElementById("hiddenTr1").style.display="";
            document.getElementById("hiddenTr2").style.display="";
            document.getElementById("hiddenTr3").style.display="";
            document.getElementById("hiddenTr4").style.display="";
            document.getElementById("hiddenTr5").style.display="";
            document.getElementById("hiddenTr6").style.display="";
            document.getElementById("hiddenTr7").style.display="";
            document.getElementById("hiddenTr8").style.display="";
            document.getElementById("hiddenTr9").style.display="";
            document.getElementById("hiddenTr10").style.display="";
            document.getElementById("hiddenTr11").style.display="";
        }
		if(userRole=="A"){
        	document.getElementById("hiddenTr12").style.display="none";
        }else{
        	document.getElementById("hiddenTr12").style.display="";
        }
    }

    function initial(){
        var currentForm = document.forms["updateUserForm"];
        var userRole=currentForm.elements["userModel.userRole"].value;
        if(userRole=="A"){
            document.getElementById("hiddenTr1").style.display="none";
            document.getElementById("hiddenTr2").style.display="none";
            document.getElementById("hiddenTr3").style.display="none";
            document.getElementById("hiddenTr4").style.display="none";
            document.getElementById("hiddenTr5").style.display="none";
            document.getElementById("hiddenTr6").style.display="none";
            document.getElementById("hiddenTr7").style.display="none";
            document.getElementById("hiddenTr8").style.display="none";
            document.getElementById("hiddenTr9").style.display="none";
            document.getElementById("hiddenTr10").style.display="none";
            document.getElementById("hiddenTr11").style.display="none";
        }
		if(userRole=="A"){
        	document.getElementById("hiddenTr12").style.display="none";
        }else{
        	document.getElementById("hiddenTr12").style.display="";
        }
    }
</script>
<div id='updateUserFormDiv'>
<s:form name="updateUserForm" action="">
<s:hidden name="userModel.createId"/>
<s:hidden name="userModel.createDt"/>
<table align="center" cellpadding="0" cellspacing="0" class="body_content full_width">
<tr>
    <td align="left" valign="bottom" class="main_page_content_icon" width="4%">
        <img src='<c:url value="/images/body-icon_check.gif"/>' width="29" height="44">
    </td>
    <td valign="bottom" class="page_title_bg" width="96%"><span class="page_title"><s:text
            name="label.user.edit"/></span></td>
</tr>
<tr>
<td class="subcontent">&nbsp;</td>
<td class="subcontent">
<table class="sectionBorder" width="100%">
<br><br><br>
<tr>
    <td class="form_label_padded" width="10%" nowrap><s:text name="label.userId"/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:property value="userModel.userId"/>
        <s:hidden name="userModel.userId"/>
    </td>
</tr>
<tr>
    <td class="form_label_padded" width="10%" nowrap><s:text name="label.userName"/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:textfield name="userModel.userName" maxlength="25"/>
    </td>
</tr>
<tr>
    <td class="form_label_padded" width="10%" nowrap><s:text name="label.password"/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:password name="userModel.userPassword" maxLength="25"/>
    </td>
</tr>
<tr>
    <td class="form_label_padded" width="10%" nowrap><s:text name="label.confirm.password"/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:password name="userModel.confirmPassword" maxLength="25"/>
    </td>
</tr>
<tr>
    <td class="form_label_padded" width="10%" nowrap><s:text name="label.userRole"/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:select list="#attr.roleList" name="userModel.userRole" listKey="codeId" listValue="codeDesc" onchange="javascript:changeUserRole();"/>
    </td>
</tr>
<tr id="hiddenTr1">
    <td class="form_label_padded" width="10%" nowrap><s:text name="label.userDept"/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:select list="#attr.deptList" name="userModel.deptId" listKey="codeId" listValue="codeDesc"/>
    </td>
</tr>
<tr id="hiddenTr2">
    <td class="form_label_padded" width="10%" nowrap><s:text name="label.recPermission"/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:checkbox name="userModel.permission1" fieldValue="Y" value="%{userModel.checkPermission1}"/>
        <codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,01"/>
    </td>
</tr>
<tr id="hiddenTr3">
    <td class="form_label_padded" width="10%" nowrap>&nbsp;</td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:checkbox name="userModel.permission2" fieldValue="Y" value="%{userModel.checkPermission2}"/>
        <codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,02"/>
    </td>
</tr>
<tr id="hiddenTr4">
    <td class="form_label_padded" width="10%" nowrap>&nbsp;</td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:checkbox name="userModel.permission3" fieldValue="Y" value="%{userModel.checkPermission3}"/>
        <codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,03"/>
    </td>
</tr>
<tr id="hiddenTr5">
    <td class="form_label_padded" width="10%" nowrap>&nbsp;</td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:checkbox name="userModel.permission4" fieldValue="Y" value="%{userModel.checkPermission4}"/>
        <codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,04"/>
    </td>
</tr>
<tr id="hiddenTr6">
    <td class="form_label_padded" width="10%" nowrap>&nbsp;</td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:checkbox name="userModel.permission5" fieldValue="Y" value="%{userModel.checkPermission5}"/>
        <codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,05"/>
    </td>
</tr>
<tr id="hiddenTr7">
    <td class="form_label_padded" width="10%" nowrap>&nbsp;</td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:checkbox name="userModel.permission6" fieldValue="Y" value="%{userModel.checkPermission6}"/>
        <codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,06"/>
    </td>
</tr>
<tr id="hiddenTr8">
    <td class="form_label_padded" width="10%" nowrap>&nbsp;</td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:checkbox name="userModel.permission7" fieldValue="Y" value="%{userModel.checkPermission7}"/>
        <codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,07"/>
    </td>
</tr>
<tr id="hiddenTr9">
    <td class="form_label_padded" width="10%" nowrap>&nbsp;</td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:checkbox name="userModel.permission8" fieldValue="Y" value="%{userModel.checkPermission8}"/>
        <codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,08"/>
    </td>
</tr>
<tr id="hiddenTr10">
    <td class="form_label_padded" width="10%" nowrap>&nbsp;</td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:checkbox name="userModel.permission9" fieldValue="Y" value="%{userModel.checkPermission9}"/>
        <codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,09"/>
    </td>
</tr>
<tr id="hiddenTr11">
    <td class="form_label_padded" width="10%" nowrap>&nbsp;</td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
        <s:checkbox name="userModel.permission10" fieldValue="Y" value="%{userModel.checkPermission10}"/>
        <codelookup:codeDesc codeType="CODE_TYPE_DESC" filterName="CODE_FILTER" filterParams="ACCESS_TYPE,10"/>
    </td>
</tr>
</tr>
<tr id="hiddenTr12">
    <td class="form_label_padded" width="10%" nowrap><s:text name="label.title.view.permission"/></td>
    <td class="form_label_padded" width="2%">:</td>
    <td class="txtData" align="left">
    	<s:radio name="userModel.viewAllInd" list="%{viewTypeList}" listKey="value" listValue="label" value="%{userModel.viewAllInd}"/>
    </td>
</tr>
<tr>
    <td class="txtData" colspan="3">
        <input type="button" class="button" value="<s:text name='label.save'/>" onclick="saveRecord();">
        <input type="button" class="button" value="<s:text name='label.back'/>" onclick="cancelRecord();">
    </td>
</tr>
</table>
</td>
</tr>
</table>
</s:form>
</div>
<script type="text/javascript">
    initial();
</script>



